package com.dongdong.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdong.data.Page;
import com.dongdong.mapper.TbContentCategoryMapper;
import com.dongdong.pojo.TbContentCategory;
import com.dongdong.pojo.TbContentCategoryExample;
import com.dongdong.service.ConCategoryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.aspectj.lang.annotation.AfterReturning;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Arrays;
import java.util.List;

@Service
@org.springframework.stereotype.Service
public class ConCategoryServiceImpl implements ConCategoryService {
    @Autowired
    private TbContentCategoryMapper tbContentCategoryMapper;

    @Override
    public Page<TbContentCategory> selectConCategoryList(String name, Integer pageNum, Integer pageSzie) {
        PageHelper.startPage(pageNum,pageSzie);
        TbContentCategoryExample tc = new TbContentCategoryExample();
        tc.createCriteria().andNameLike(name);
        List<TbContentCategory> categoryList = tbContentCategoryMapper.selectByExample(tc);
        PageInfo<TbContentCategory> info = new PageInfo<>(categoryList);
        return new Page<>(info.getPageNum(),info.getPageSize(),info.getTotal(),info.getPages(),info.getList());
    }

    @Override
    public int insert(TbContentCategory tbContentCategory) {
        return tbContentCategoryMapper.insert(tbContentCategory);
    }

    @Override
    public TbContentCategory selectById(Long id) {
        return tbContentCategoryMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateInfo(TbContentCategory tbContentCategory) {
        return  tbContentCategoryMapper.updateByPrimaryKey(tbContentCategory);
    }

    @Override
    public int deleteBatch(Long[] ids) {
        TbContentCategoryExample te = new TbContentCategoryExample();
        te.createCriteria().andIdIn(Arrays.asList(ids));
        return tbContentCategoryMapper.deleteByExample(te);
    }

    @Override
    public List<TbContentCategory> selectAll() {
        return tbContentCategoryMapper.selectByExample(null);
    }
}
